package org.senzacontrollo.designPatterns.bridge;

import java.util.Collection;

public abstract class Matrix {
	
	protected int rows,cols;
	protected Collection<MatrixCell> data;
	
	
	protected Matrix(int rows, int cols, Collection<MatrixCell> data) {
		super();
		this.rows = rows;
		this.cols = cols;
		this.data = data;
	}
	
	protected MatrixCell getPosition(int row, int col){
	
		if( row < 0 || row >= rows || col <0 || col >= cols){
			throw new MatrixIndexOutOfBoundsException();
		}
		
		for(MatrixCell cell : data){
			
			if(row == cell.getRow() && col == cell.getCol())
				return  cell;;
	
		}
		return null;
	
	}
	
	protected MatrixCell createPosition(int row, int col){
		
		MatrixCell cell = getPosition(row, col);
		
		if (cell == null)
			cell = new MatrixCell(row, col);
		
		data.add(cell);
		return cell;
		
	}
	
	protected void deletePosition(MatrixCell cellToDelete){
		data.remove(cellToDelete);
		
	}
	
	protected abstract void put(int row,int col,int value);
	
	protected abstract MatrixCell get(int row,int col);
	
	
	


}
